﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace QuangNgai.nhaplieu.vanban
{
    public partial class frmTruongTinVanBan : DevExpress.XtraEditors.XtraForm
    {
        public frmTruongTinVanBan()
        {
            InitializeComponent();
        }

        private void frmTruongTinVanBan_Load(object sender, EventArgs e)
        {
            this.hsfieldtypeTableAdapter.Fill(this.lTQNDataSet.Hsfieldtype);
            this.vbfieldsTableAdapter.Fill(this.lTQNDataSet.Vbfields);

        }

        private void gvTTVB_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            vbfieldsBindingSource.EndEdit();
            vbfieldsTableAdapter.Update(lTQNDataSet.Vbfields);
        }

        private void gvTTVB_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                gvTTVB_RowUpdated(sender, null);
            }
        }

        private void gcTTVB_EmbeddedNavigator_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
        {
            if (e.Button.ButtonType == NavigatorButtonType.Remove)
            {
                e.Handled = true; // by-pass default handle
                if (MessageBox.Show("Bạn có muốn xóa trường tin này?", "Xác nhận xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) ==
                  DialogResult.Yes)
                {

                    vbfieldsBindingSource.RemoveCurrent();
                    vbfieldsTableAdapter.Update(lTQNDataSet.Vbfields);
                }
            }
        }

        private void gvTTVB_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {
            if (gvTTVB.FocusedColumn.Name == "colFullfieldname")
                if (e.Value.ToString() == "" || e.Value == null)
                {
                    e.Valid = false;
                }
        }

        private void gvTTVB_InvalidValueException(object sender, DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs e)
        {
            e.ExceptionMode = ExceptionMode.DisplayError;
            e.ErrorText = "Tên trường tin không được trống";
            e.WindowCaption = "Lỗi nhập liệu";
        }
    }
}